//
//  QZChoiceHairStylistVc.m
//  WeiWeiHaircut
//
//  Created by 上官惠阳 on 15/12/12.
//  Copyright © 2015年 超群. All rights reserved.
//

#import "QZChoiceHairStylistVc.h"
#import "MyAppointmentCell.h"
#import "PersonInfoViewController.h"
#import "DesignerModel.h"
#import "UIImageView+WebCache.h"
@interface QZChoiceHairStylistVc ()

@end

@implementation QZChoiceHairStylistVc

- (void)viewDidLoad {
    [super viewDidLoad];
    [self titleWithSting:@"设计师选择"];
    
    [self addBtnOnNavWithTitle:@"返回" andImageName:@"返回" andTarget:self andAction:@selector(backAction) andFrame:CGRectMake(0, 0, 45, 20) andDirection:left];
    [self createTableViewWithPlainStyle:YES andSeparatorStyleNone:YES andBackGroudImageName:nil];
    self.tableView.backgroundColor = BACKGROUDCOLOR;
    [self registCellWithNib:@"MyAppointmentCell" addIdentifier:@"appointCell" addHeight:103];
//    [self loadData];
    [self requestData];
}
-(void)loadCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
    MyAppointmentCell *appointCell = (MyAppointmentCell *)cell;
    DesignerModel *model = self.tableSource[indexPath.row];
    appointCell.nameLabel.text = model.nickName;
    appointCell.signLabel.text = [NSString stringWithFormat:@"签名:%@",model.sign];
    [appointCell.headImage sd_setImageWithURL:[NSURL URLWithString:model.userimg] placeholderImage:[UIImage imageNamed:@"1123.jpg"]];
    
    appointCell.tapHeadBlock = ^(id obj){
        PersonInfoViewController *infoVc = [[PersonInfoViewController alloc]init];
        [self.navigationController pushViewController:infoVc animated:YES];
    };
}
- (void)actionAtIndexPath:(NSIndexPath *)indexPath{
    DesignerModel *model = self.tableSource[indexPath.row];
    if (_myBlock) {
        _myBlock(model);
    }
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark- 获取设计师列表
-(void)requestData
{
    int appoint_type;
    if ([_storeStay isEqualToString:@"店铺"]) {
        appoint_type = 1;
    }else{
        appoint_type = 2;
    }
    NSString *url = [NSString stringWithFormat:@"%@%@",newPublicURL,@"HairOrder.GetAppointDesigner"];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:@(appoint_type) forKey:@"appoint_type"];
    if (!_model.id) {//上门

        [dic setObject:@(4000) forKey:@"raidus"];
        [dic setObject:@(_model.longitude) forKey:@"longitude"];
        [dic setObject:@(_model.latitude) forKey:@"latitude"];
    }else{//店铺
        [dic setObject:@(_model.id) forKey:@"shop_id"];
    }
    
    [self.request QZRequest_POST:url parameters:dic tagNSString:@"获取设计师列表" stopRequest:YES isSerializer:NO isCache:NO];
}
-(void)request_POST_FinishValue:(id)value tagNSString:(NSString *)tag
{
    NSLog(@"%@",value);
    if ([tag isEqualToString:@"获取设计师列表"]) {
        if ([value[@"data"][@"status"] integerValue] != 100) {
            [[iToast makeText:@"无数据"] show];
            return;
        }
        NSArray *array = value[@"data"][@"data"][@"list"];
        
        for (NSDictionary *dic in array) {
            
            DesignerModel *model = [[DesignerModel alloc] initWithDictionary:dic error:nil];
            [self.tableSource addObject:model];
        }
        [self.tableView reloadData];
    }
}
-(void)loadData
{
    [self.tableSource setArray:@[@"",@"",@"",@""]];
    [self.tableView reloadData];
}
-(void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
